package com.yyfax.ph.personal.feedback;

import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.IView;
import com.yyfax.infrastructure.mvp.Presenter;
import com.yyfax.infrastructure.mvp.PresenterFactory;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class FeedBackPresenter extends Presenter<FeedBackModel, FeedBackPresenter.View> {

	public static class Generator implements PresenterFactory<FeedBackPresenter> {
		@Override
		public FeedBackPresenter create() {
			return new FeedBackPresenter();
		}
	}

	private View mView;

	@Override
	public void attach(View view) {
		mView = view;
		mModel = new FeedBackModel();
		EventAgent.register(this);
	}

	@Override
	public void detach() {
		mView = null;
		mModel = null;
		EventAgent.unregister(this);
	}

	public interface View extends IView {
		void sendFeedBackSuccess(String tips);

		void sendFeedBackFailure(String tips);
	}


	public void feedBack(String content) {
		execute(content);
	}

	@Subscribe(threadMode = ThreadMode.MAIN)
	public void noticeResult(FeedBackModel.FeedBackResult event) {
		if (isResponseSuccess(event)) {
			mView.sendFeedBackSuccess(event.getMsg());
		} else {
			mView.sendFeedBackFailure(event.getMsg());
		}
	}
}
